<?php
/**
 * 简历管理
 */

class EAdmin_Page_StateActive extends EAdmin_Page_Abstract
{
    private $resumeDb;
    private function loadDb()
    {
        $this->resumeDb = Db_Resume::instance();
    }
    public function validate(ME_Request $input, ME_Response $output)
    {
    	$euserInfo = Libs_EUser::getLoginStatus($input,$output);
	$output->euid = 
	$input->euid =
		$euid = $euserInfo[0];
	if(empty($euid)){
		header("location:index.php?c=login");
	}

	$this->loadDb();
	$sql = "select id, name from resume_state where eid='{$euid}' or eid='-1'";	
	$result = $this->resumeDb->getAll($sql);

	$state_arr = array();
	if($result){
		foreach($result as $state){
			$state_arr[$state['id']] = $state['name'];
		}
	}
	
	$output->state = $state_arr;

        return true;
    }
    
    public function doDefault(ME_Request $input, ME_Response $output)
    {
	$euid = $input->euid;
	$state = Libs_EState::getEResumeState($euid);
	if(!empty($state)){
		$state_arr = explode(",",$state);
	}else{
		$state_arr = array();
	}

	$output->state_arr = $state_arr;
	$output->setTemplate("StateActive");
    }

    public function doSave(ME_Request $input, ME_Response $output)
    {
    	$euid = $input->euid;
	$state = $input->post("state");

	$result = Libs_EState::saveEResumeState(array('eid'=>$euid, 'state'=>$state));

	if($result){
		echo "<script>alert('保存成功！');window.location='index.php?c=StateActive';</script>";
		exit;
	}
    }

    public function doAdd(ME_Request $input, ME_Response $output)
    {
        $euid = $input->euid;
        $state_add = $input->post("state");

	if(empty($state_add)){
		echo "<script>alert('请填写简历状态');window.location='index.php?c=StateActive';</script>";
                exit;
	}

	$this->loadDb();
	$sql = "select id from resume_state where name='{$state_add}'and eid={$euid} limit 1";
	$state_id = $this->resumeDb->getOne($sql);
	if($state_id){
		echo "<script>alert('该简历状态已存在！');window.location='index.php?c=StateActive';</script>";
               	exit;
	}


	$arr = array('name'=>$state_add, "eid"=>$euid);
	$colArr = array('name', 'eid');
	$insertId = Libs_DBHelper::insertItem(array(
                'db' => $this->resumeDb,
                'tableName' => 'resume_state',
                'addItem' => $arr,
                'colArr' => $colArr,
                'debug' => false,
                ));
		
        if($insertId){
                echo "<script>alert('保存成功！');window.location='index.php?c=StateActive';</script>";
                exit;
        }
    }

}
